<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="./script/rem.js"></script>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/new.css" />
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script></head>
    <script type="text/javascript" src="./script/aui-tab.js" ></script>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
</head>
<body>
    <style>
        body{background:url() no-repeat; background-size:cover;}
    </style>
    <header class="head" style="padding-top:0.4rem;">
        <div class="head-l" tapmode onclick="closeWin()"><i class="fa fa-angle-left"></i></div>
        <h3 id="title">专题</h3>
        <div class="head-r"></div>
    </header>
    <div class="head-d" style="padding-top:0.4rem"></div>

    <div id="list">
        <!-- <div class="special-banner"> -->
        <!-- <img src="image/new/special-banner.jpg"> -->
<!--             <dl>
                <dt>热销专题</dt>
                <dd>商城优惠产品 </dd>
            </dl> -->
<!--         </div>
        <div class="specia-t"><img src="image/new/special-1-t.png"></div>
        <ul class="specia-1">
            <li><img src="image/new/special-1-1.png"></li>
            <li><img src="image/new/special-1-2.png"></li>
            <li><img src="image/new/special-1-3.png"></li>
        </ul> -->

    </div>
    <div class="specia-t"><img src="image/new/special-2-t.png"></div>
    <ul class="specia-2" id="product">
<!--         <li>
            <img src="image/new/goods.jpg">
            <dl>
                <dt>澳大利亚·毛孔脏东西浮出来·麦卢...</dt>
                <dd>￥166.00</dd>
            </dl>
        </li> -->
    </ul>

</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/index.js"></script>
<script type="text/template" id="template">
    <div class="special-banner">
        <img src="{{=it.banner}}">
    </div>
    {{? it.list_recommend.length != 0}}
    <div class="specia-t"><img src="image/new/special-1-t.png"></div>
    <ul class="specia-1">
        {{? it.list_recommend[0]}}
        <li onclick="check_detail({{=it.list_recommend[0].id}});"><img src="{{=it.list_recommend[0].picture}}"></li>
        {{?}}
        {{? it.list_recommend[1]}}
        <li onclick="check_detail({{=it.list_recommend[1].id}});"><img src="{{=it.list_recommend[1].picture}}"></li>
        {{?}}
        {{? it.list_recommend[2]}}
        <li onclick="check_detail({{=it.list_recommend[2].id}});"><img src="{{=it.list_recommend[2].picture}}"></li>
        {{?}}
    </ul>
    {{?}}
</script>
<script type="text/template" id="product_template">
    {{~it:value:index}}
    <li onclick="check_detail({{=value.id}})">
        <img src="{{=value.image}}">
        <dl>
            <dt>{{=value.title}}</dt>
            {{? value.specialId == 5}}
            <dd>{{=value.coin}} 金币</dd>
            {{??}}
            <dd>￥{{=value.price_current}}</dd>
            {{?}}
        </dl>
    </li>
    {{~}}
</script>
<script type="text/javascript">

    apiready = function(){
        var title = api.pageParam.title;
        $('#title').text(title);
        specialId = api.pageParam.id;
        loadData(specialId);
        loadSpecialProduct(specialId);
    }

    function loadData(id) {
        api.ajax({
            url: webAddress + '/api/topic/'+id+'/show',
            method: 'get',
            data: {}
        }, function(ret, err) {
            if (ret) {
                // alert(JSON.stringify( ret ));
                if (ret.data) {
                    $("body").css("background-image","url("+ret.data.picture_bg+")");
                    templateFun(ret.data);
                }
            } else {
                // alert(JSON.stringify(err));
            }
        });
    }

    function loadSpecialProduct(id){

        // 进度提示框
        api.showProgress({
            title: '努力加载中...',
            text: '请稍等...',
            modal: false
        });

        api.ajax({
            url: webAddress + '/api/topic/'+id+'/product',
            method: 'get',
            data: {
                page: 1,
                row: 90,
            }
        }, function(ret, err) {
            if (ret) {
                // alert(JSON.stringify( ret ));
                api.hideProgress();
                if (ret.data) {
                    if (id == 5) {
                        for (var i = 0; i < ret.data.length; i++) {
                            ret.data[i]['specialId'] = 5;
                        }
                    }
                    templateFun_product(ret.data);
                }
            } else {
                // alert(JSON.stringify(err));
                api.hideProgress();
            }
        });
    }

    // 模板赋值函数(专题详情)
    function templateFun(data){
        var template = $api.byId('template');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');
        $api.html(list, html);
    }

    // 模板赋值函数(专题商品)
    function templateFun_product(data){
      var template = $api.byId('product_template');
      var dotFn = doT.template(template.innerHTML);
      var html = dotFn(data);
      var list = $api.byId('product');
      if (data.length) {
       $api.html(list, html);
   }else{
    var html = '<h2 style="padding:1rem; text-align:center; color:#999; font-size:0.5rem;">暂无商品</h2>';
    list.innerHTML = html;
}

}

    // 点击当月商品
    function check_detail(id) {

      var token = $api.getStorage('token');
      if(!token){
        api.openWin({
            name: 'login',
            url: './login.html',
            pageParam: {
                name: 'test'
            }
        });
        return;
    }

    if (specialId == 5) {
        api.openWin({
            name: 'month_goods_details',
            url: './month_goods_details.html',
            pageParam: {
                id: id
            }
        });
    }else{
        api.openWin({
            name: 'goods_details',
            url: './goods_details.html',
            pageParam: {
                id: id
            }
        });
    }
}

function order_details() {
    api.openWin({
        name: 'order_details',
        url: './order_details.html',
    });
}
function closeWin(){
    // api.closeWin({
    // });
    api.closeToWin({
        name: 'root'
    });
}
</script>
</html>